package mr.ali.video.web.controller;


import com.github.pagehelper.PageInfo;
import mr.ali.video.web.Exception.R;
import mr.ali.video.web.mapper.CollectionMapper;
import mr.ali.video.web.model.Collection;
import mr.ali.video.web.service.ICollectionService;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;

/**
 * <p>
 * 前端控制器
 * </p>
 *
 * @author Mr-ali
 * @since 2025-08-03
 */
@RestController
@RequestMapping("/web/collection")
public class CollectionController {
    @Resource
    private ICollectionService collectionService;

    @Resource
    private CollectionMapper collectionMapper;

    @GetMapping("/select")
    public PageInfo<Collection> select(Integer pageNum, Integer pageSize) {
        return collectionService.getCollectionList(pageNum, 20);
    }

    @GetMapping("/update/displayed")
    public R<Integer> updateDisplayed(Integer id, Integer displayed) {
        return R.ok(collectionService.updateDisplayed(id, displayed));
    }

    @GetMapping("/deleteById")
    public R<Integer> deleteById(Integer id) {
        return R.ok(collectionService.deleteById(id));
    }

    @GetMapping("/selectById")
    public R<Collection> selectById(Integer id) {
        return R.ok(collectionService.selectById(id));
    }

    @GetMapping("/insert")
    public R<Integer> insert(Collection collection) {
        return R.ok(collectionService.insert(collection));
    }

    @GetMapping("/selectByTypeId")
    public Integer selectByTypeId(Integer type) {
        return collectionMapper.CountByTypeId(type);
    }
}
